package com.zc.dao;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.zc.domain.FaultItem;
import com.zc.domain.FaultStatisticsItem;
import com.zc.domain.Item;

@Repository
public interface IFaultDao {
	@Select("SELECT channel,gzname,timestamp FROM gz ORDER BY timestamp DESC LIMIT 7;")
	@Results({
		@Result(column = "timestamp",property = "timeStamp"),
		@Result(column = "channel",property = "channel"),
		@Result(column = "gzname",property = "name")
	})
	List<FaultItem> getCurFault();
	
	@Select("SELECT gzname,timestamp FROM gz WHERE channel='${channel}' ORDER BY timestamp DESC;")
	@Results({
		@Result(column = "timestamp",property = "timeStamp"),
		@Result(column = "gzname",property = "name")
	})
	List<FaultItem> getAllFault(@Param("channel") String channel);
	
	@Select("SELECT gzname,COUNT(gzname) AS num FROM (SELECT gzname FROM gz WHERE channel='${channel}' AND timeStamp>'${beginDate}') AS g GROUP BY gzname;")
	@Results({
		@Result(column = "gzname",property = "name"),
		@Result(column = "num",property = "num")
	})
	List<FaultStatisticsItem> getCurFaultStat(@Param("channel") String channel, @Param("beginDate") String beginDate);
	
	@Select("SELECT gzname,COUNT(gzname) AS num FROM (SELECT gzname FROM gz WHERE channel='${channel}' AND TimeStamp>'${beginDate}' AND TimeStamp<'${endDate}') AS g GROUP BY gzname;")
	@Results({
		@Result(column = "gzname",property = "name"),
		@Result(column = "num",property = "num")
	})
	List<FaultStatisticsItem> select(@Param("channel") String channel,@Param("beginDate") String beginDate,@Param("endDate") String endDate);
}
